<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="zh-CN">
<head>
    <meta charset="GB18030">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/main.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/carousel.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor: pointer;
        }

        table tbody tr:nth-child(odd) {
            background: #F4F4F4;
        }

        table tbody td:nth-child(even) {
            color: #C00;
        }

        th {
            text-align: center
        }

    </style>
</head>

<body>
<div class="navbar-wrapper ">
    <%--动态导入另一个jsp页面，作用：将公共使用的部分提取出来，然后使用动态导入
              动态导入是不会导入include页面的编译指令的，而是仅仅将被导入页面的body内容插入本页面。--%>
    <jsp:include page="admin-header.jsp"></jsp:include>
</div>
<div class="container-fluid">
    <div class="row">
        <%--动态导入另一个jsp页面，作用：将公共使用的部分提取出来，然后使用动态导入
                     动态导入是不会导入include页面的编译指令的，而是仅仅将被导入页面的body内容插入本页面。--%>
        <jsp:include page="admin-left.jsp"></jsp:include>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form class="form-inline" action=""
                          method="post"
                          role="form" style="float:left;">
                        <button type="button" class="btn btn-success" onclick="location.replace('/addadmin-page')">
                            <i
                                class="glyphicon glyphicon-plus"></i> 新增管理员
                        </button>
                    </form>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table table-responsive table-hover" align="center">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th>登陆账户</th>
                                <th>称呼</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody align="center" id="idList">
                            <c:forEach var="admin" items="${tbAdminPageInfo.list}">
                                <tr>
                                    <td>${admin.adminId}</td>
                                    <td><span data-toggle="tooltip" title="登录账号">${admin.adminAccount}</span></td>
                                    <td><span data-toggle="tooltip" title="称呼">${admin.adminName}</span></td>
                                    <td>
                                        <c:if test="${admin.adminLocked==false}">
                                            <button type="button" class="btn btn-success btn-xs"
                                                    data-toggle="tooltip"
                                                    title="账号可登陆">未锁定
                                            </button>
                                        </c:if>
                                        <c:if test="${admin.adminLocked==true}">
                                            <button type="button" class="btn btn-warning btn-xs"
                                                    data-toggle="tooltip"
                                                    title="账号不可登陆">已锁定
                                            </button>
                                        </c:if>

                                    </td>
                                    <c:if test="${admin.adminLocked==true}">
                                        <td>
                                            <button type="button" class="btn btn-info btn-xs" data-toggle="tooltip"
                                                    title="解锁" onclick="suodingOk(${admin.adminId},this)"><i
                                                class=" glyphicon glyphicon-check"></i>
                                            </button>
                                        </td>
                                    </c:if>
                                    <c:if test="${admin.adminLocked==false}">
                                        <td>
                                            <button type="button" class="btn btn-danger btn-xs"
                                                    data-toggle="tooltip"
                                                    title="锁定" onclick="suodingNo(${admin.adminId},this)"><i
                                                class=" glyphicon glyphicon-remove"></i>
                                            </button>
                                        </td>
                                    </c:if>
                                </tr>
                            </c:forEach>
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="10" align="right">
                                    当前${tbAdminPageInfo.pageNum }页,总${tbAdminPageInfo.pages }页,总${tbAdminPageInfo.total }条记录
                                </td>
                            </tr>
                            <tr>
                                <td colspan="10" align="center">
                                    <ul class="pagination">
                                        <li><a
                                            href="${pageContext.request.contextPath}/tbAdmin/searchAdmins?page=1">首页</a>
                                        </li>
                                        <!-- 判断是否有上一页，以便显示点击按钮 -->
                                        <c:if test="${tbAdminPageInfo.hasPreviousPage }">
                                            <li>
                                                <a href="${pageContext.request.contextPath}/tbAdmin/searchAdmins?page=${tbAdminPageInfo.pageNum-1 }"
                                                   aria-label="Previous">
                                                    <span aria-hidden="true">&laquo;</span>
                                                </a>
                                            </li>
                                        </c:if>
                                        <!-- 遍历页码 -->
                                        <c:forEach items="${tbAdminPageInfo.navigatepageNums }" var="page_Num">
                                            <c:if test="${page_Num == tbAdminPageInfo.pageNum }">
                                                <li class="active"><a href="#">${page_Num }</a></li>
                                            </c:if>
                                            <c:if test="${page_Num != tbAdminPageInfo.pageNum }">
                                                <li><a
                                                    href="${pageContext.request.contextPath}/tbAdmin/searchAdmins?page=${page_Num }">${page_Num}</a>
                                                </li>
                                            </c:if>
                                        </c:forEach>
                                        <!-- 判断是否有下一页 -->
                                        <c:if test="${tbAdminPageInfo.hasNextPage }">
                                            <li>
                                                <a href="${pageContext.request.contextPath}/tbAdmin/searchAdmins?page=${tbAdminPageInfo.pageNum+1 }"
                                                   aria-label="Next">
                                                    <span aria-hidden="true">&raquo;</span>
                                                </a>
                                            </li>
                                        </c:if>

                                        <li><a
                                            href="${pageContext.request.contextPath}/tbAdmin/searchAdmins?page=${tbAdminPageInfo.pages }">末页</a>
                                        </li>
                                    </ul>

                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${pageContext.request.contextPath}/resources/jquery/jquery-2.1.1.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/script/docs.min.js"></script>
<script type="text/javascript">

    $(function () {

        $("[data-toggle='tooltip']").tooltip();

        $(".list-group-item").click(function () {
            if ($(this).find("ul")) {
                $(this).toggleClass("tree-closed");
                if ($(this).hasClass("tree-closed")) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
    });

    /*锁定账户操作*/
    function suodingOk(adminId, obj) {
        //alert("账户id====" + userId)
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbAdmin/updateStatus',

                data: {
                    adminId: adminId,
                    adminLocked: 0  //表示已激活
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        location.reload()
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    };

    /*解锁操作*/
    function suodingNo(adminId, obj) {
        //alert("账户id====" + userId)
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbAdmin/updateStatus',

                data: {
                    adminId: adminId,
                    adminLocked: 1  //1表示已注销
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        //location.replace('/tbUser/searchUser')
                        location.reload()
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    };
</script>
</body>
</html>
